<?php

namespace app\admin\controller;

use think\Db;

class Job extends Base
{

    /**
     * 添加岗位
     */
    public function addJob()
    {
        $data = [];
        input('name') ? $data['name'] = input('name') : $this->err('缺少岗位');
        input('only') != null ? $data['only'] = input('only') : $this->err('缺少岗位类型');
 //       input('jobSalary') != null ? $data['jobSalary'] = input('jobSalary') : $this->err('缺少岗位工资！');
        input('maxSalary') != null ? $data['maxSalary'] = input('maxSalary') : $this->err('缺少最大岗位工资！');
        input('minSalary') != null ? $data['minSalary'] = input('minSalary') : $this->err('缺少最小岗位工资！');
        input('parentId') != null ? $data['parentId'] = input('parentId') : true;
        input('sort') != null ? $data['sort'] = input('sort') : true;
        $data['createTime'] = createTime();

        $res = model('job')->editData($data);
        $res ? $this->suc($res) : $this->err('添加岗位失败');
    }

    /**
     * 修改岗位
     */
    public function editJob()
    {
        $data = [];
        input('id') ? $data['id'] = input('id') : $this->err('缺少岗位主键');
        input('name') != null ? $data['name'] = input('name') : $this->err('缺少岗位');
        input('only') != null ? $data['only'] = input('only') : $this->err('缺少岗位类型');
 //       input('jobSalary') != null ? $data['jobSalary'] = input('jobSalary') : $this->err('缺少岗位工资！');
        input('maxSalary') != null ? $data['maxSalary'] = input('maxSalary') : $this->err('缺少最大岗位工资！');
        input('minSalary') != null ? $data['minSalary'] = input('minSalary') : $this->err('缺少最小岗位工资！');
        input('parentId')!= null ? $data['parentId'] = input('parentId') : true;
        input('sort') != null ? $data['sort'] = input('sort') : true;
        $res = model('job')->editData($data, $data['id']);
        $res ? $this->suc($res) : $this->err('修改岗位失败');
    }

    /**
     * 查询岗位详情
     */
    public function getJobDetail()
    {
        $data = [];
        input('id') ? $data['id'] = input('id') : $this->err('缺少岗位主键');

        $res = model('job')->where($data)->find();
        $res ? $this->suc($res) : $this->err('查询失败');
    }

    /**
     * 删除岗位
     */
    public function delJob()
    {
        $where = [];
        input('id') ? $where['id'] = input('id') : $this->err('缺少岗位主键');

        $res = model('job')->where($where)->delete();
        $res ? $this->suc($res) : $this->err('删除岗位失败');

    }

    /**
     * 查询岗位
     */
    public function getJobList()
    {
        $where = [];
        input('name') ? $where['name']=['like','%'.input('name').'%'] : true;

        $res = model('job')->getListByPage($where, 10, '', 'sort desc');
        $res ? $this->suc($res) : $this->err('查询失败');

    }
    /**
     * 查询全部岗位
     */
    public function getAllJob()
    {

        $res = model('job')->field('createTime', true)->order('sort desc')->select();
        $res ? $this->suc($res) : $this->err('查询失败');

    }

}
